<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Promise</title>
</head>

<body>
    <script>
        let one = new Promise(
            (resolve, reject) => {
                console.log('Promise')
                resolve()
            }
        )
        one.then(() => console.log('resolved'))
        // console.log('Hi!');



        //调用resolve(1)以后，后面的console.log(2)还是会执行,会首先打印出来
        //因为立即 resolved 的 Promise 是在本轮事件循环的末尾执行，总是晚于本轮循环的同步任务。
        new Promise(
            (resolve, reject) => {
                return resolve(1)
                console.log(2)
            }
        ).then(
            r => console.log(r),
            console.log(3)
            );

        const promise = new Promise(function (resolve, reject) {
            resolve('ok');
            throw new Error('test');
        });
        promise.then(function (value) { console.log(value) }).catch(function (error) { console.log(error) });

    </script>
</body>

</html>